package com.neusoft.a312cxy.android18cxy.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.a312cxy.android18cxy.R;
import com.neusoft.a312cxy.android18cxy.activity.EditpersonActivity;
import com.neusoft.a312cxy.android18cxy.activity.GuanzhuActivity;
import com.neusoft.a312cxy.android18cxy.activity.MyshaituActivity;
import com.neusoft.a312cxy.android18cxy.activity.OrderlistActivity;
import com.neusoft.a312cxy.android18cxy.bean.MySelfBean;
import com.neusoft.a312cxy.android18cxy.model.MySelfModel;
import com.squareup.picasso.Picasso;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Young on 2017/9/25.
 */


public class mySelfFragment extends Fragment
{
    private Button myorder;
    private Button myshaitu;
    private Button myself;
    private Button myguanzhu;
    private ImageView photo;
    private TextView realname,sex,tel,intro;
    private String realname1,tel1,intro1,sex1,photo1;
 //   private MySelfBean MySelf;
    private int id;

    private View view=null;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view=inflater.inflate(R.layout.fragment_person, container, false);
        initView();
        GetMySelf();
      //  saveDate();
      //  MySelfModel model=new MySelfModel();
        return  view;
    }
/*
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {

        if(resultCode == RESULT_OK)
        {
            //TODO执行刷新操作
        }

    }*/
    public  void initView(){
        realname=(TextView)view.findViewById(R.id.realname);
       // recyclerView= (RecyclerView) view.findViewById(R.id.ac);
        sex=(TextView)view.findViewById(R.id.sex);

        tel=(TextView)view.findViewById(R.id.tel) ;
        intro=(TextView) view.findViewById(R.id.intro);
        myorder=(Button) view.findViewById(R.id.myorder) ;
        myshaitu=(Button) view.findViewById(R.id.myshaitu);
        myself=(Button)view.findViewById(R.id.xiugai) ;
        myguanzhu=(Button) view.findViewById(R.id.myguanzhu);
        photo=(ImageView) view.findViewById(R.id.photo);

        myself.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                Intent intent=new Intent(getActivity(), EditpersonActivity.class);
                intent.putExtra("name",realname1);
                intent.putExtra("photo",photo1);
                intent.putExtra("userid",id);
                intent.putExtra("tel",tel1);
                intent.putExtra("intro",intro1);
                intent.putExtra("sex",sex1);
                startActivity(intent);
               // getActivity().finish();


            }

        });
        myorder.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick( View view){
                Intent intent=new Intent(getActivity(), OrderlistActivity.class);
                intent.putExtra("userid",id);
                startActivity(intent);
            }
        });
        myshaitu.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick( View view){
                Intent intent=new Intent(getActivity(), MyshaituActivity.class);
                intent.putExtra("userid",id);
                startActivity(intent);
            }
        });
        myguanzhu.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick( View view){
                Intent intent=new Intent(getActivity(), GuanzhuActivity.class);
                intent.putExtra("userid",id);
                startActivity(intent);
            }
        });




    }

    @Override
    public void onResume(){
        super.onResume();
        //发网络请求
    }

/*    public void saveDate(){
        Intent intent = getIntent();
        Bundle  bundle =  intent.getExtras();
        id = bundle.getInt("id");
          sid=getSharedPreferences("userinfo", Context.MODE_PRIVATE);
           user_id=sid.getString("user_id", "");
    }*/
public void GetMySelf(){
    final MySelfModel MySelfModel=new MySelfModel();
    Call<MySelfBean> call=MySelfModel.getMySelf("19");
    call.enqueue(new Callback<MySelfBean>() {
        @Override
        public void onResponse(Call<MySelfBean> call, Response<MySelfBean> response) {
            MySelfBean mySelfBean=response.body();
            if(!mySelfBean.getPhoto().isEmpty())
            {
                Picasso.with(getActivity()).load("http://172.24.10.175/workout/Uploads/"+mySelfBean.getPhoto()).into(photo);
            }
/*              else
                {
                    ClubInfoActivity.clubthumb.setImageResource(R.drawable.ic_club);
                }*/

/*                if(!Club.getClubthumb().isEmpty())
                {
                    Picasso.with(ClubInfoActivity.this).load("http://172.24.10.175/workout/Uploads/"+Club.getClubthumb()).into(clubthumb);
                }*/
/*                else{
                   ImageView.clubthumb.setImageResource(R.drawable.ic_club);
                }*/
            realname.setText(mySelfBean.getRealname());
            realname1=mySelfBean.getRealname();
            sex.setText(mySelfBean.getSex());
            sex1=mySelfBean.getSex();
            tel.setText(mySelfBean.getTel());
            tel1=mySelfBean.getTel();
            intro.setText(mySelfBean.getIntro());
            intro1=mySelfBean.getIntro();
            photo1=mySelfBean.getPhoto();

        }
        /*            @Override
                    public void onResponse(Call<List<ClubInfo>> call, Response<List<ClubInfo>> response) {
                        List<ClubInfo> data=response.body();
                        recyclerView.setAdapter(new ClubcourseAdapter(ClubInfoActivity.this,data));
                    }*/
        @Override
        public void onFailure(Call<MySelfBean> call, Throwable t) {

        }



    });

}


    }
